package vn.appsmobi.loader;

import android.content.Context;

import java.util.ArrayList;

import org.json.JSONObject;

import vn.appsmobi.model.AppInfo;
import vn.appsmobi.model.CategoryInfo;
import vn.appsmobi.model.ListAppInfo;
import vn.appsmobi.ulti.Constant;
import vn.appsmobi.ulti.Log;
import vn.appsmobi.ulti.Request;

public class DeveloperLoader extends BaseLoader
{
	private String agency;
	private String agencyId;
	private String listapp_type;
	
    public DeveloperLoader(Context paramContext)
    {
        super(paramContext);
    }
    
    public void setAgency(String agency)
    {
        this.agency = agency;
    }
    
    
    
    public void setAgencyId(String agencyid)
    {
        this.agencyId = agencyid;
    }
    
    public void setListAppType(String type)
    {
        this.listapp_type = type;
    }
    
    protected BaseResult getResultInstance()
    {
        return new Result();
    }
    
    protected BaseLoader.UpdateTask getUpdateTask()
    {
        return new TopAppUpdateTask();
        
    }
    
    protected BaseResult parseResult(JSONObject json, BaseResult result)
    throws Exception
    {
        Result localResult = (Result)result;
        localResult.mTopAppInfos = ListAppInfo.valueOfAray(json);
        return localResult;
    }
    
    private class TopAppUpdateTask extends BaseLoader.UpdateTask
    {
        private TopAppUpdateTask()
        {
            super();
        }
        
        @Override
        protected Request getRequest() {
        	Log.v(String.format(Constant.GET_LISTAPP_URL,DeveloperLoader.this.listapp_type,DeveloperLoader.this.agencyId)  );
            return new Request(String.format(Constant.GET_LISTAPP_URL,DeveloperLoader.this.listapp_type,DeveloperLoader.this.agencyId)  );
        }
        
    }
    
    public static final class Result extends BaseResult
    {
        public ArrayList<AppInfo> mTopAppInfos;
        
        protected int getCount()
        {
            int count = 0;
            if (this.mTopAppInfos != null)
            count = this.mTopAppInfos.size();
            return count;
        }
        
        public BaseResult shallowClone()
        {
            Result localResult = new Result();
            localResult.mTopAppInfos = this.mTopAppInfos;
            return localResult;
        }
    }
    
    
}